package com.dongdongshop.controller;

import com.dongdongshop.data.Page;
import com.dongdongshop.data.Result;
import com.dongdongshop.pojo.TbAddress;
import com.dongdongshop.pojo.TbGoods;
import com.dongdongshop.pojo.TbItem;
import com.dongdongshop.pojo.TbUser;
import com.dongdongshop.service.EsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("es")
public class EsController {
    @DubboReference
    private EsService esService;

    @RequestMapping("toShow")
    public String toShow(String title, Model model){
        model.addAttribute("title",title);
        return "search";
    }


    @RequestMapping("searchDoc")
    @ResponseBody
    public Result searchDoc(String title,
                          @RequestParam(defaultValue = "1")Integer pageNum,
                          @RequestParam(defaultValue = "12")Integer pageSize){
        Page<Map<String,Object>> itemList = esService.searchDoc(title,pageNum,pageSize);
        return Result.ok().setData(itemList);
    }
}
